/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uloha4.main;

import java.awt.geom.Point2D;
import uloha4.entities.Node;
import uloha4.entities.Point;

/**
 *
 * @author Tomique
 */
public class MyMath {

    public static boolean intersectsNode(Node node, Point2D mouse, int nodeSize) {
        int x0 = node.pos.x;
        int y0 = node.pos.y;

        int x = (int) mouse.getX();
        int y = (int) mouse.getY();

        int radius = java.lang.Math.round(nodeSize * node.getScale() / 2.0f);

        if (((x - x0) * (x - x0) + (y - y0) * (y - y0)) <= radius * radius) {
            return true;
        }
        return false;
    }

    public static Point plus(Point p1, Point p2) {
        return new Point(p1.x + p2.x, p1.y + p2.y);
    }

    public static Point minus(Point p1, Point p2) {
        return new Point(p1.x - p2.x, p1.y - p2.y);
    }

    public static Point times(Point p, float s) {
        return new Point((int) (p.x * s), (int) (p.y * s));
    }

    public static float size(Point p) {
        return (float) Math.sqrt((p.x * p.x) + (p.y * p.y));
    }
}
